package com.ruoyi.web.controller.base;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BScore;
import com.ruoyi.base.service.IBScoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 得分Controller
 *
 * @author ruoyi
 * @date 2024-03-24
 */
@RestController
@RequestMapping("/base/score")
public class BScoreController extends BaseController {
    @Autowired
    private IBScoreService bScoreService;

    /**
     * 查询得分列表
     */
    @PreAuthorize("@ss.hasPermi('base:score:list')")
    @GetMapping("/list")
    public TableDataInfo list(BScore bScore) {
        startPage();
        List<BScore> list = bScoreService.selectBScoreList(bScore);
        return getDataTable(list);
    }

    /**
     * 导出得分列表
     */
    @PreAuthorize("@ss.hasPermi('base:score:export')")
    @Log(title = "得分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BScore bScore) {
        List<BScore> list = bScoreService.selectBScoreList(bScore);
        ExcelUtil<BScore> util = new ExcelUtil<BScore>(BScore.class);
        util.exportExcel(response, list, "得分数据");
    }

    /**
     * 获取得分详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:score:query')")
    @GetMapping(value = "/{scoreId}")
    public AjaxResult getInfo(@PathVariable("scoreId") Long scoreId) {
        return success(bScoreService.selectBScoreByScoreId(scoreId));
    }

    /**
     * 新增得分
     */
    @PreAuthorize("@ss.hasPermi('base:score:add')")
    @Log(title = "得分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BScore bScore) {
        return toAjax(bScoreService.insertBScore(bScore));
    }

    /**
     * 修改得分
     */
    @PreAuthorize("@ss.hasPermi('base:score:edit')")
    @Log(title = "得分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BScore bScore) {
        return toAjax(bScoreService.updateBScore(bScore));
    }

    /**
     * 删除得分
     */
    @PreAuthorize("@ss.hasPermi('base:score:remove')")
    @Log(title = "得分", businessType = BusinessType.DELETE)
    @DeleteMapping("/{scoreIds}")
    public AjaxResult remove(@PathVariable Long[] scoreIds) {
        return toAjax(bScoreService.deleteBScoreByScoreIds(scoreIds));
    }
}
